﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Service;
using User.Model;
using User.Data;
using Core.UnitOfWork;
using User.Repository;
using User.IService;

namespace User.Service
{
    public class ResourceService : NodeService<Resource, UserContext>, IResourceService
    {
        public Resource GetResouceTree()
        {
            using (UserContext content = new UserContext())
            {
                IUnitOfWork unitOfWork = new UnitOfWork(content);
                IResourceRepository rep = new ResourceRepository(unitOfWork);
                Resource root = rep.GetRoot();
                GenerateChildren(root);
                return root;
            }
        }

        private void GenerateChildren(Resource resource)
        {
            foreach (var r in resource.Children)
            {
                GenerateChildren(r);
            }
        }

    }
}
